'use strict';

const { Controller } = require('egg');

class ProHelpController extends Controller {
  // 添加帮助信息
  async createNeedHelp () {
    const ctx = this.ctx;
    const info = ctx.request.body;
    try {
      const res = await ctx.service.proHelp.createNeedHelp(info);
      ctx.body = {
        code: 200,
        mag: '添加成功',
        data: res
      };
    } catch (error) {
      ctx.body = {
        code: 500,
        msg: '添加失败',
        data: null
      };
    }
  }
  // 展示帮助信息
  async showProHelp () {
    const ctx = this.ctx;
    const { id } = ctx.query;
    let userId = id;
    try {
      let drugList = await this.app.mysql.query(
        `select * from provideDrug where userId=${userId}`
      );
      const res = drugList;
      ctx.body = {
        code: 200,
        mag: 'success',
        data: res
      };
    } catch (error) {
      ctx.body = {
        code: 500,
        msg: 'fail',
        data: null
      };
    }
  }
  //修改帮助信息
  async editProHelp () {
    const { ctx } = this;
    // console.log(ctx.request.body);
    const { id, isSolve } = ctx.request.body;
    try {
      const result = await ctx.service.proHelp.editProHelp(id, isSolve);
      ctx.body = {
        code: 200,
        msg: '修改成功',
        data: null
      };
    } catch (error) {
      ctx.body = {
        code: 500,
        msg: '修改失败',
        data: null
      };
    }
  }
}

module.exports = ProHelpController;
